Micron Document




Conditional (computer programming)
part 14/26 · 46.2 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Up to Fortran 77, the language Fortran has had an arithmetic if statement which jumps to one of three labels depending on whether its argument e is e < 0, e = 0, e > 0. This was the earliest conditional statement in Fortran.cite-ref-fortran77-11-0[11]

Syntax

IF (e) label1, label2, label3

Where e is a numeric expression of type integer, real, or double precision.

Semantics

This is equivalent to this sequence, where e is evaluated only once.

IF (e .LT. 0) GOTO label1
IF (e .EQ. 0) GOTO label2
IF (e .GT. 0) GOTO label3

Stylistics

Arithmetic if is an unstructured control statement, and is not used in structured programming.

In practice it has been observed that most arithmetic IF statements reference the following statement with one or two of the labels.

This was the only conditional control statement in the original implementation of Fortran on the IBM 704 computer. On that computer the test-and-branch op-code had three addresses for those three states. Other computers would have "flag" registers such as positive, zero, negative, even, overflow, carry, associated with the last arithmetic operations and would use instructions such as 'Branch if accumulator negative' then 'Branch if accumulator zero' or similar. Note that the expression is evaluated once only, and in cases such as integer arithmetic where overflow may occur, the overflow or carry flags would be considered also.

Object-oriented implementation in Smalltalk

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────